#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
#include <stdio.h>

#define BUFSIZE 1024

int main() {
    int fd[2];
    int ret = pipe(fd);
    int status;
    assert(ret != -1);
    pid_t pid = fork();
      if (pid == 0) {
        // 子进程
        char str[] = "hello";
        char buf[BUFSIZE];
        write(fd[1], str, sizeof str);
        sleep(1);
        read(fd[0], buf, sizeof buf);
        puts(buf);
    } else {
        // 父进程
        char str[] = "world";
        char buf[BUFSIZE];
        read(fd[0], buf, BUFSIZE);
        puts(buf);
        write(fd[1], str, sizeof str);
        wait(&status);
    }
    return 0;
}